package com.apache.funds.service.plugins;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.apache.api.manager.PluginConnector;
import com.apache.api.vo.ParamsVo;
import com.apache.api.vo.ResultEntity;
import com.apache.database.constant.Validator;
import com.apache.database.model.Page;
import com.apache.funds.common.FundsToolsUtil;
import com.apache.funds.entity.SvmFlowing;
import com.apache.funds.manager.SvmFlowingManager;
import com.apache.funds.util.Constants;

/**
 * 查询流水明细
 * @author Administrator
 */
public class FundsFlowingPlugin implements PluginConnector {
	private Logger log = LoggerFactory.getLogger(getClass());

	private SvmFlowingManager svmFlowingManager;

	public void setSvmFlowingManager(SvmFlowingManager svmFlowingManager) {
		this.svmFlowingManager = svmFlowingManager;
	}

	@Override
	public Object execute(ParamsVo param) throws Exception {
		ResultEntity entity = new ResultEntity();
		entity.setResult("true");
		entity.setMessage("查询失败");
		entity.setEntity("false");

		String pageSize = Validator.getDefaultStr(String.valueOf(param.getParams("pageSize")), "0");
		String pageIndex = Validator.getDefaultStr(String.valueOf(param.getParams("pageIndex")), "0");

		ParamsVo<SvmFlowing> voQuery = new ParamsVo<SvmFlowing>();
		voQuery.setParams(param.getParams());
		voQuery.setMethodKey("ByService");
		voQuery.setParams("orderBy", " create_time desc");
		SvmFlowing flowing = new SvmFlowing();
		FundsToolsUtil.getInstance().convert2Bean(param.getParams(), flowing);
		voQuery.setObj(flowing);
		if ("0".equals(pageSize) || "0".equals(pageIndex)) {
			List<SvmFlowing> list = svmFlowingManager.getList(voQuery);
			entity.setEntity(list);
		} else {
			Page pageList = svmFlowingManager.getPageInfo(voQuery);
			entity.setEntity(pageList);
		}
		entity.setResult("true");
		entity.setMessage(Constants.Msg.F000+"查询完成");
		return entity;
	}
}
